/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.webapp.form.core;

import com.blandware.atleap.webapp.form.BaseForm;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * <p>This form bean contains Map-backed properties, because of possibility to
 * edit multiple ContentFieldValues.</p>
 * <p><a href="ContentFieldValueForm.java.html"><i>View Source</i></a></p>
 * <p/>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.14 $ $Date: 2007/07/04 13:45:32 $
 * @struts.form name="contentFieldValueForm"
 */
public class ContentFieldValueForm extends BaseForm implements Serializable {

	/**
	 * List of mappings <code>localeIdentifier -&gt; id</code>
	 */
	protected SortedMap idMap = new TreeMap();

	/**
	 * List of mappings <code>localeIdentifier -&gt; value</code>
	 */
	protected SortedMap valueMap = new TreeMap();

	/**
	 * List of mappings <code>localeIdentifier -&gt; version</code>
	 */
	protected SortedMap versionMap = new TreeMap();

	/**
	 * List of mappings <code>localeIdentifier -&gt; locale</code>
	 */
	protected SortedMap localeMap = new TreeMap();

	/**
	 * ID of owner content fields
	 */
	protected String contentFieldId;

    // Following properties are for creation of indexed field (or just a field)
    // with values

    /**
     * ID of owner localizable
     */
    protected String ownerId;

    /**
     * Field identifier (used to create ordinary field)
     */
    protected String identifier;

    /**
     * Field indexed identifier (used to create indexed field)
     */
    protected String indexedIdentifier;

    /**
     * Current index
     */
    protected String currentIndex;

    /**
     * Field type
     */
    protected String fieldType;

    /**
     * Definition for owner
     */
    protected String definition;

    /**
	 * Default empty constructor.
	 */
	public ContentFieldValueForm() {
	}

	/**
	 * Returns map of IDs
	 *
	 * @return map of ids
	 */
	public SortedMap getIdMap() {
		return idMap;
	}

	/**
	 * Sets map of IDs
	 *
	 * @param idMap map to set
	 */
	public void setIdMap(SortedMap idMap) {
		this.idMap = idMap;
	}

	/**
	 * Returns ID of CFV by specified key
	 *
	 * @param key Key to get ID for
	 * @return id corresponding to given key
	 */
	public Object getId(String key) {
		return idMap.get(key);
	}

	/**
	 * Sets ID for specified key
	 *
	 * @param key Key to set ID for
	 * @param id  ID to set
	 */
	public void setId(String key, Object id) {
		idMap.put(key, id);
	}

	/**
	 * Returns map of values
	 *
	 * @return map of values
	 */
	public SortedMap getValueMap() {
		return valueMap;
	}

	/**
	 * Sets map of values
	 *
	 * @param valueMap Map to set
	 */
	public void setValueMap(SortedMap valueMap) {
		this.valueMap = valueMap;
	}

	/**
	 * Returns value of CFV by specified key
	 *
	 * @param key Key to return value for
	 * @return value corresponding to given key
	 */
	public Object getValue(String key) {
		return valueMap.get(key);
	}

	/**
	 * Sets value for specified key
	 *
	 * @param key   Key to set value for
	 * @param value Value to set
	 */
	public void setValue(String key, Object value) {
		valueMap.put(key, value);
	}

	/**
	 * Returns map of versions
	 *
	 * @return map of versions
	 */
	public SortedMap getVersionMap() {
		return versionMap;
	}

	/**
	 * Sets map of versions
	 *
	 * @param versionMap Map to set
	 */
	public void setVersionMap(SortedMap versionMap) {
		this.versionMap = versionMap;
	}

	/**
	 * Returns version of CFV by specified key
	 *
	 * @param key Key to return version for
	 * @return version corresponding to given key
	 */
	public Object getVersion(String key) {
		return versionMap.get(key);
	}

	/**
	 * Sets version for specified key
	 *
	 * @param key     Key to set version for
	 * @param version Version to set
	 */
	public void setVersion(String key, Object version) {
		versionMap.put(key, version);
	}

	/**
	 * Returns locale map
	 *
	 * @return Locale map
	 */
	public SortedMap getLocaleMap() {
		return localeMap;
	}

	/**
	 * Sets locale map
	 *
	 * @param localeMap Locale map to set
	 */
	public void setLocaleMap(SortedMap localeMap) {
		this.localeMap = localeMap;
	}

	/**
	 * Returns locale associated with specified identifier
	 * @param key Key to search locale by
	 * @return Locale associated with specified key
	 */
//	public Object getLocale(String key) {
//		return localeMap.get(key);
//	}

	/**
	 * Sets locale for specified identifier
	 * @param key Identifier of locale
	 * @param locale Locale itself
	 */
//	public void setLocale(String key, Object locale) {
//		localeMap.put(key, locale);
//	}

	/**
	 * Gets ID of owner content field
	 *
	 * @return field ID
	 */
	public String getContentFieldId() {
		return contentFieldId;
	}

	/**
	 * Sets ID of owner content field
	 *
	 * @param contentFieldId ID of content field to set
	 */
	public void setContentFieldId(String contentFieldId) {
		this.contentFieldId = contentFieldId;
	}

    /**
     * Returns owner ID.
     *
     * @return owner ID
     */
    public String getOwnerId() {
        return ownerId;
    }

    /**
     * Sets owner ID.
     *
     * @param ownerId ID to set
     */
    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    /**
     * Returns field identifier (used to create ordinary field).
     *
     * @return field identifier
     */
    public String getIdentifier() {
        return identifier;
    }

    /**
     * Sets field identifier (used to create ordinary field).
     * 
     * @param identifier identifier to set
     */
    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    /**
     * Returns indexed field identifier (used to create indexed field).
     *
     * @return identifier
     */
    public String getIndexedIdentifier() {
        return indexedIdentifier;
    }

    /**
     * Sets indexed field identifier (used to create indexed field).
     *
     * @param indexedIdentifier identifier to set
     */
    public void setIndexedIdentifier(String indexedIdentifier) {
        this.indexedIdentifier = indexedIdentifier;
    }

    /**
     * Returns current index.
     *
     * @return current index
     */
    public String getCurrentIndex() {
        return currentIndex;
    }

    /**
     * Sets current index.
     *
     * @param currentIndex index to set
     */
    public void setCurrentIndex(String currentIndex) {
        this.currentIndex = currentIndex;
    }

    /**
     * Returns field type.
     *
     * @return field type
     */
    public String getFieldType() {
        return fieldType;
    }

    /**
     * Sets field type.
     *
     * @param fieldType type to set
     */
    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    /**
     * Returns owner's definition.
     *
     * @return definition
     */
    public String getDefinition() {
        return definition;
    }

    /**
     * Sets owner's definition.
     *
     * @param definition definition to set
     */
    public void setDefinition(String definition) {
        this.definition = definition;
    }

    /**
	 * Returns number of CFVs saved in this bean
	 *
	 * @return Size of list of IDs
	 */
	public int getNumberOfValues() {
		return idMap.size();
	}

	/**
	 * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.idMap = new TreeMap();
		this.valueMap = new TreeMap();
		this.versionMap = new TreeMap();
	}
}
